home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / ICONTENT.ICN < prev    next >
Text File  |  1992-11-26  |  2KB  |  72 lines

  1. ############################################################################
  2. #
  3. #    File:     icontent.icn
  4. #
  5. #    Subject:  Program to list Icon procedures
  6. #
  7. #    Author:   Robert J. Alexander
  8. #
  9. #    Date:     August 17, 1990
  10. #
  11. ###########################################################################
  12. #
  13. #  Builds a list, in Icon comment format, of procedures and records
  14. #  in an Icon source file.
  15. #
  16. #  Multiple files can be specified as arguments, and will be processed
  17. #  in sequence.  A file name of "-" represents the standard input file.
  18. #  If there are no arguments, standard input is processed.
  19. #
  20. #  usage: icontent <options> <Icon source file>...
  21. #    options:    -s    sort names alphabetically (default is in
  22. #                order of occurrence)
  23. #            -l    list in single column (default is to list
  24. #                in multiple columns)
  25. #
  26.  
  27. link options,colmize
  28.  
  29. procedure main(arg)
  30.    local opt,linear,Colmize,Sort,namechar,fn,f,names,line,name,type
  31.    #
  32.    #  Process command line options and file names.
  33.    #
  34.    opt := options(arg,"sl")
  35.    linear := opt["l"]
  36.    Colmize := if \opt["l"] then proc("!",1) else colmize
  37.    Sort := if \opt["s"] then sort else 1
  38.    if *arg = 0 then arg := ["-"] # if no arguments, standard input
  39.    namechar := &letters ++ &digits ++ "_"
  40.    #
  41.    #  Loop to process files.
  42.    #
  43.    every fn := !arg do {
  44.       f := if fn == "-" then &input else {
  45.      if not (fn[-4:0] == ".icn") then fn ||:= ".icn"
  46.      open(fn) | stop("Can't open input file \"",fn,"\"")
  47.          }
  48.       names := []
  49.       write("#  Procedures and Records",
  50.       if f === &input then "" else " in " || fn,":")
  51.       #
  52.       #  Loop to process lines of file (in string scanning mode).
  53.       #
  54.       while line := read(f) do line ? {
  55.      if    (tab(many(' \t')) | "")\1 &
  56.            type := (=("procedure" | "record"))\1 &
  57.            (tab(many(' \t')) | "")\1 & name := tab(many(namechar)) &
  58.            (tab(many(' \t')) | "")\1 & ="(" then {
  59.         put(names,name || if type == "procedure" then "()" else ".")
  60.         }
  61.      }
  62.       #
  63.       #  Close this file.
  64.       #
  65.       close(&input ~=== f)
  66.       every write("#    ",Colmize(Sort(names),71))
  67.       }
  68.    #
  69.    #  End of program.
  70.    #
  71. end
  72.